/* -*- mode: c++ -*- */
/**
 * @file   array_one.h
 * @author billjeff <http://billjeff.blogbus.com>
 * @date   Dec/6/2007
 * 
 * 
 * This code is based on SVG Lib Board Lib(http://libboard.sf.net).
 * You can use this code under the licence of GPL V3.
 *
 * class svgForArray1 is used for one dimension array in our program.
 * This code is part of project SVG-Container(http://code.google.com/p/svg-container/)
 */

#ifndef _ARRAY_ONE_H_
#define _ARRAY_ONE_H_

#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdarg>
#include <cmath>
#include "include/Board.h"

using namespace std ;
using namespace BoardLib ;


namespace SVGCont{
  
  template<typename T>
  class svgForArray1{
  private:
    static const int INFOSIZE = 256 ;
    static const int ARRAYSIZE = 256 ;
    static const double UNITSIZE = 0.02 ;
    static const double HEIGHT = 0.025 ;
    char info_[INFOSIZE] ; // Store the info of current array;
    Board b ; // Drawing board
    int c_ ; // count of actions performed on the array;
    double sx_, lx_, y_ ; // position on the board
    int dim_ ; // dimension of arrays, just support 1 array for this class;
    int nx_, ny_ ; // length of each dimension of array;
    float fontsize_ ;
  protected:
    //Print the step just before the array in SVG
    void printStep() ;
    // trans() is used to transfer every v to char string.
    // note about buffer size
    void trans( char *val, double v ){
      sprintf( val, "%lf", v ) ;      
    }
    void trans( char *val, int v ){
      sprintf( val, "%d", v ) ;
    }
    void trans( char *val, const string &v ){
      strcpy( val, v.c_str() ) ;
    }
    void trans( char *val, long long v ){
      sprintf( val, "%lld", v ) ;
    }
    void trans( char *val, const char *v ){
      strcpy( val, v ) ;
    }
    // Draw array value in SVG.
    void drawVal( const char *val ) ;
    // Draw each rectangle of the array.
    void drawUnit( double &x, double &y, const T &v, bool f = false ) ;
    // Draw the whole array by this function
    void drawLine( double &x, double &y, int n, const T *arr, int px = -1 ) ;
    void drawLine( double &x, double &y, int n, int *arr, int an, const T *aval, bool f = false ) ;
  public:
    svgForArray1( const char * info, int nx )  ;
    void iniSVG( T const * arr ) ;
    void resizeArray( int len, T const * arr ) ;
    void updateSVG( const T *arr, int n, ... ) ;
    void writeSVG( const char *name ) ;
  } ;
}

#include "array_one.cpp"

#endif
